#CircleSineWave.pyde
r1 = 100 #radius of big circle
r2 = 10  #radius of small circle
t = 0 #time variable
circleList = []

def setup():
    size(1000,800)
    background(0,0,0)
    
def draw():
    global t, circleList
    background(0,0,0)
    
    #move to left-center of screen
    translate(width/6, height/2)
    noFill() #don't color in the circle

    stroke(80, 80, 80)  # x and y axis
    line(-200, 0, 1000, 0)
    line(0, -500, 0, 800)

    stroke(255, 255, 255)
    ellipse(0,0,2*r1,2*r1)


    #circling ellipse:
    fill(255,0,0)  #red
    y = r1*sin(t)
    y = -y
    x = r1*cos(t)
    #add point to list:
    circleList.insert(0,y)
    ellipse(x,y,r2,r2)
    line(0, 0, x, y)
    
    noFill()
    startRad = TWO_PI - ( t % TWO_PI)
    arc(0, 0, r1/4, r1/4, startRad, TWO_PI)

    
    stroke(0,255,0)  #green for the horizontal line
    line(x,y,200,y)
    fill(0,255,0) #green for the ellipse
    ellipse(200,y,10,10)
    
    if len(circleList)>500: 
        # circleList.remove(circleList[-1])
        lastIdx = len(circleList) - 1
        circleList.pop(lastIdx)


    #loop over circleList to leave a trail:
    for i,c in enumerate(circleList):
        #small circle for trail:
        # ellipse(200+i,c,2,2)
        if i-1>=0:
            line(200+i,c, 200+i-1, circleList[i-1])

    t += 0.025
